<?php /* Smarty version 2.6.20, created on 2013-05-25 01:50:46
         compiled from _core/pagecommon/_mvc/_control/handlepagecustomerold.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/pagecommon/_mvc/_control/handlepagecustomerold.tpl', 110, false),)), $this); ?>
﻿function HandlePageCustomerOld(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  this._customerId = (options && options.id) ? options.id : null;
  this._orderTrackId = (options && options.track) ? options.track : null;
  this._showReminderNote = (options && options.showReminderNote) ? options.showReminderNote : 0;
  this._isAdmin = (options && options.isAdmin) ? options.isAdmin : false;
  
  this._gui.order.branchHistory.style.display = 'none';
  this._gui.cancelCustomer.style.display = 'none';
  this._gui.order.printOrders.style.display = 'none';
  this._gui.order.print.style.display = 'none';
  this._gui.order.modify.style.display = 'none';
  this._gui.order.finish.style.display = 'none';
  this._gui.order.cancel.style.display = 'none';
  this._gui.order.payment.print.style.display = 'none';
  this._gui.order.dateTitle.style.display = 'none';
  this._gui.order.produceHistory.style.display = 'none';
  this._gui.customer.rc.style.visibility = 'hidden';
  DlmanageUtils.initialise(document.body);
  this._createElements();
};

HandlePageCustomerOld.prototype._createElements = function() {
  /* 预先显示 */
  this._gui.customerNo.appendChild(document.createTextNode(DlmanageUtils.customerId(this._customerId)));
  var pos = [window.screen.width / 2, window.screen.height / 5];
  MiscUtils.load(this._popupBox, pos, ' Loading Massive Data... ');

  this._loadData();
};

HandlePageCustomerOld.prototype._loadData = function() {
  this._customer = null;
  this._sources = null;
  this._receptions = null;
  this._cultures = null;
  this._ceremonys = null;
  this._produces = null;
  this._refunds = null;
  
  this._retrieveCustomer();
  this._retrieveSources();
  this._retrieveReceptions();
  this._retrieveCultures();
  this._retrieveCeremonys();
  this._retrieveProduces();
  this._retrieveRefunds();
};

HandlePageCustomerOld.prototype._verifyData = function() {
    if (this._customer && this._sources && this._receptions && this._cultures && this._ceremonys && this._produces && this._refunds) {  
  
    this._updateElements();
  }
};

HandlePageCustomerOld.prototype._retrieveSources = function() {
  var _self = this;
  /*new RequestUtils()._read('isource', null, null, null, null, null, null, function(result, params) { _self._sources = result.data;
                                                                                                     _self._verifyData.call(_self);
                                                                                                   }, null);*/
                                                                                                   
  new RequestUtils()._mysql('isource', null, function(result, params) { _self._sources = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});                                                                                                     
};

HandlePageCustomerOld.prototype._retrieveReceptions = function() {
  var _self = this;
  /*new RequestUtils()._read('ireception', null, null, null, null, null, null, function(result, params) { _self._receptions = result.data;
                                                                                                        _self._verifyData.call(_self);
                                                                                                      }, null);
*/

  new RequestUtils()._mysql('ireception', null, function(result, params) { _self._receptions = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});  
};

HandlePageCustomerOld.prototype._retrieveCultures = function() {
  var _self = this;
  /*new RequestUtils()._read('iculture', null, null, null, null, null, null, function(result, params) { _self._cultures = result.data;
                                                                                                      _self._verifyData.call(_self);
                                                                                                    }, null);*/
                                                                                                    
  new RequestUtils()._mysql('iculture', null, function(result, params) { _self._cultures = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});                                                                                                      
};

HandlePageCustomerOld.prototype._retrieveCeremonys = function() {
  var _self = this;
  /*new RequestUtils()._read('iceremony', null, null, null, null, null, null, function(result, params) { _self._ceremonys = result.data;
                                                                                                       _self._verifyData.call(_self);
                                                                                                     }, null);*/
                                                                                                     
  new RequestUtils()._mysql('iceremony', null, function(result, params) { _self._ceremonys = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});                                                                                                       
};

HandlePageCustomerOld.prototype._retrieveCustomer = function() {
  var _self = this, str = '';
  if (this._customerId) {
    //if (this._operator.type != '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
     // str = ' AND c.cancelled = 0';
    //}
    
    /*new RequestUtils()._read('customer', null, 'd.oid = ' + this._customerId + str, null, null, null, null, function(result, params) { _self._customer = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                       if (!_self._customer) {
                                                                                                                                         window.alert('NO CUSTOMER ' + _self._customerId);
                                                                                                                                         history.back();
                                                                                                                                         return;
                                                                                                                                       }
                                                                                                                                       _self._verifyData.call(_self);
                                                                                                                                     }, null);*/
   var cond = (this._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' || this._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') ? 1 : 0;
   var args = '&oid=' + this._customerId + '&cond=' + cond; 
  new RequestUtils()._mysql('v1customer', args, function(result, params) { _self._customer = (result.data.length == 1) ? result.data[0] : null;
                                                                        if (!_self._customer) {
                                                                          window.alert('NO CUSTOMER ' + _self._customerId);
                                                                          history.back();
                                                                          return;
                                                                        }
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});                                                                                                                                          
                                                                                                                                     
  } else {
    this._customer = v1customer.instance();
    this._customer.createdDate = this._now;
    this._customer.sales = this._operator;
    this._verifyData();
  }
};

HandlePageCustomerOld.prototype._retrieveProduces = function() {
  var _self = this;
  if (this._customerId) {
    var joins = '&selects=1' + '&purchaseitems=1' + '&preconusers=1' + '&events=1' + '&tracks=1' + '&produces=0' + '&notes=1';
    var args = '&s=9999&c=d.branch = \'<?php echo ((is_array($_tmp=@BRANCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
\' AND d.customerId = ' + this._customerId + joins;
    new RequestUtils()._mysql('produce', args, function(result, params) { _self._produces = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, { php: Constant.FACTORY + '/customphp/produceread.php'});

  
  
  } else {
    this._produces = [];
  }
};

HandlePageCustomerOld.prototype._retrieveRefunds = function() {
  var _self = this;
  if (this._customerId) {
   /* new RequestUtils()._read('expense', null, 'd.payee=' + this._customerId + ' AND ' + 'd.refundNo != 0', null, null, null, null, function(result, params) { _self._refunds = result.data;
                                                                                                                                                              _self._verifyData.call(_self);
                                                                                                                                                            }, null);
 */
  var args = '&oid=' + this._customerId; 
  new RequestUtils()._mysql('expense', args, function(result, params) { _self._refunds = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});   
  } else {
    this._refunds = [];
  }
};

HandlePageCustomerOld.prototype._updateElements = function() {
  var _self = this, table, tr, td;
  DlmanageUtils.clear(this._gui);
  this._popupBox._close();
  
  //2011年9月30日 09:23:55start
  if (this._customer.is_ecn == 1) {
    this._gui.ecndiv.style.backgroundColor = 'yellow';
  } else {
    this._gui.ecndiv.style.backgroundColor = '';
  }
  this._gui.ecn.checked = (this._customer.is_ecn == 1) ? true: false;
  this._gui.ecn.onchange = function() { if (this.checked) {
                                         _self._customer.is_ecn = 1;
                                       } else {
                                         _self._customer.is_ecn = 0;
                                       }
                                       new RequestUtils()._mwrite('customerecn', [_self._customer], [], function() { location.reload(); }, {pos: DOMUtils.findPos(this)});
  };
  
  this._gui.createDate.style.fontSize = '14px';
  this._gui.createDate.style.color = '#734e52';
  this._gui.createDate.style.fontFamily = 'Arial';
  this._gui.createDate.style.fontWeight = 'bold';
  this._gui.createDate.appendChild(document.createTextNode('Created on'));
  span = document.createElement('span');
  span.style.width = '25px';
  span.style.fontSize = '12px';
  span.style.color = '#000';
  span.style.fontFamily = 'Arial';
  span.style.fontWeight = 'bold';
  span.style.margin = '0 3px';
  span.appendChild(document.createTextNode(SimpleDate.format(this._customer.createdDate)));
  this._gui.createDate.appendChild(span);
  this._gui.createDate.appendChild(document.createTextNode('By'));
  span = document.createElement('span');
  span.style.fontSize = '12px';
  span.style.color = '#000';
  span.style.fontFamily = 'Arial';
  span.style.fontWeight = 'bold';
  span.style.margin = '0 3px';
  span.appendChild(document.createTextNode(' ' + ((this._customer.userAccount) ? this._customer.userAccount : 'None')));
  this._gui.createDate.appendChild(span);  
  
  //2011年9月30日 09:24:03 end

  var back, text, jump, next;
  back = DOMUtils.createInput(null, null, 'button', '<', null);
  back.style.margin = '0 5px 0 0';
  text = DOMUtils.createInput(null, null, 'text', '', null);
  jump = DOMUtils.createInput(null, null, 'button', 'Go', null);
  next = DOMUtils.createInput(null, null, 'button', '>', null);
  next.style.margin = '0 0 0 5px';
  this._gui.search.appendChild(back);
  this._gui.search.appendChild(text);
  this._gui.search.appendChild(jump);
  this._gui.search.appendChild(next);
  text.style.width = '75px';
  text.style.height = '17px';
  text.style.margin = '0 2px 0 5px';
  text.style.borderTop= 'solid 1px #d2c4b9';
  text.style.borderLeft= 'solid 1px #d2c4b9';
  text.style.borderRight= 'solid 1px #fff';
  text.style.borderBottom= 'solid 1px #fff';
  jump.style.margin = '0 5px 0 0';
  back.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageasst&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id - 1 });
                              } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageserv&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id - 1 });
                              } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id - 1 });
                              } else {
                                location.href = '?p=pagemanager&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id - 1 });
                              }
                            };
  text.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                  if (code == 13) {
                                    if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                      location.href = '?p=pageasst&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: this.value });
                                    } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                      location.href = '?p=pageserv&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: this.value });
                                    } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                      location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: this.value });
                                    } else {
                                      location.href = '?p=pagemanager&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: this.value });
                                    }
                                  }
                                };
  jump.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageasst&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: text.value });
                              } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageserv&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: text.value });
                              } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: text.value });
                              } else {
                                location.href = '?p=pagemanager&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: text.value });
                              }
                            };
  next.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageasst&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: parseInt(_self._customer.id, 10) + 1 });
                              } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageserv&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: parseInt(_self._customer.id, 10) + 1 });
                              } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: parseInt(_self._customer.id, 10) + 1 });
                              } else {
                                location.href = '?p=pagemanager&t=pagecustomerold&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: parseInt(_self._customer.id, 10) + 1 });
                              }
                            };

                            
                            
  /*re-email 开始*/
   this._gui.order.pdfrpt.onclick = function(){
                                                   /* var r = window.confirm('Re-email Receipt, CONTINUE?');
                                                    var rpt = {};
                                                        rpt.id = _self._customer.id;
                                                        rpt.brideemail = _self._customer.brideemail;
                                                        rpt.groomemail = _self._customer.groomemail;
                                                        rpt.createDate = _self._now;
                                                        rpt.account = _self._operator;
                                                    if(r){
                                                        new RequestUtils()._mwrite('receiptpdf', [rpt], [], function() { _self._retrieveCustomer.call(_self); }, { pos: DOMUtils.findPos(this) });
                                                    }*/
                                                    
                                      var pos = DOMUtils.findPos(this);
                                      var pay1 = [];
                                      
                                      var _default ='Dear '+ _self._customer.bridename + ' & '+ _self._customer.groomname + ' , ' + "\n"+
                                                   "\n"+
                                                  'Please find the attached pdf file' + "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  'Kind Regards' + "\n"+
                                                  'Yours Sincerely ' + '<?php echo ((is_array($_tmp=@SHOPNAME)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' ;
                                                        
                                      var div = document.createElement('div');
                                      var div2 = document.createElement('div');
                                      var div3 = document.createElement('div');
                                      
                                       
                                      div2.style.marginTop = '5px';
                                      div3.style.marginTop = '5px';                                      
                                      div3.style.paddingLeft = '12px';
                                      
                                      var input = document.createElement('input');
                                      input.type='text';
                                      input.style.width = '345px';
                                      input.style.height = '30px';
                                      input.value ='Receipt for Customer '+_self._customer.id;
                                  
                                      div2.appendChild(document.createTextNode('Subject '));
                                      div2.appendChild(input);
                                      div.appendChild(div2);
                                                        

                                      var func1 = function() { 
                                          if (input.value == '') {
                                              window.alert('Subject is not null!');
                                              return;
                                            }
                                          
                                                        var rpt = {};
                                                        rpt.id = _self._customer.id;
                                                        rpt.brideemail = _self._customer.brideemail;
                                                        rpt.groomemail = _self._customer.groomemail;
                                                        rpt.createDate = _self._now;
                                                        rpt.account = _self._operator;
                                                        rpt.bodytext = pay1._text;
                                                        rpt.subject = input.value;                                          
                                           
                                          
                                          new RequestUtils()._mwrite('receiptpdf', [rpt], [], function() { _self._retrieveCustomer.call(_self); }, { pos: DOMUtils.findPos(this) });
                                          _self._popupBox2._close();
                                        };                                                                                            
                                                                                                    
                                         var func2 = function() { _self._popupBox2._close();};
                                        MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Re-email Receipt',ok:'ok',cancel:'cancel'});
                                        new DialogInput(div, pay1, { title: '',default: _default});	                                                    
                                              };
  

   this._gui.order.pdfrbf.onclick = function(){
                                                        
                                      var pos = DOMUtils.findPos(this);
                                      var pay1 = [];
                                      
                                      var _default ='Dear '+ _self._customer.bridename + ' & '+ _self._customer.groomname + ' , ' + "\n"+
                                                   "\n"+
                                                  'Please find the attached pdf file' + "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  'Kind Regards' + "\n"+
                                                  'Yours Sincerely ' + '<?php echo ((is_array($_tmp=@SHOPNAME)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' ;
                                                        
                                      var div = document.createElement('div');
                                      var div2 = document.createElement('div');
                                      var div3 = document.createElement('div');
                                      
                                       
                                      div2.style.marginTop = '5px';
                                      div3.style.marginTop = '5px';                                      
                                      div3.style.paddingLeft = '12px';
                                      
                                      var input = document.createElement('input');
                                      input.type='text';
                                      input.style.width = '345px';
                                      input.style.height = '30px';
                                      input.value ='Booking Form for Customer '+_self._customer.id;
                                  
                                      div2.appendChild(document.createTextNode('Subject '));
                                      div2.appendChild(input);
                                      div.appendChild(div2);
                                                        

                                      var func1 = function() { 
                                          if (input.value == '') {
                                              window.alert('Subject is not null!');
                                              return;
                                            }
                                          
                                           
                                                         var rbf = {};
                                                        rbf.id = _self._customer.id;
                                                        rbf.brideemail = _self._customer.brideemail;
                                                        rbf.groomemail = _self._customer.groomemail;
                                                        rbf.createDate = _self._now;
                                                        rbf.account = _self._operator;
                                                        rbf.bodytext = pay1._text;
                                                        rbf.subject = input.value;                                          
                                           
                                          
                                          new RequestUtils()._mwrite('bookformpdf', [rbf], [], function() { _self._retrieveCustomer.call(_self); }, { pos: DOMUtils.findPos(this) });
                                          _self._popupBox2._close();
                                        };                                                                                            
                                                                                                    
                                         var func2 = function() { _self._popupBox2._close();};
                                        MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Re-email Booking Form',ok:'ok',cancel:'cancel'});
                                        new DialogInput(div, pay1, { title: '',default: _default});		                                                       

                                              };
this._gui.order.enum.innerHTML='';
  var emailnum = (_self._customer.email.length == 0)? '0' : _self._customer.email.length; 
        var a = document.createElement('a');
        a.href = '#';
        a.appendChild(document.createTextNode(emailnum));
        a._edata = _self._customer.email;
        a.onclick = function() { 
              func1 = function() { _self._popupBox2._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.style.verticalAlign = 'top';
                                 div.style.width = '800px';
                                 div.style.color = '#ff0000';
                                 div.style.textAlign = 'left';
                                 div.style.padding = '4px 0 0 10px';
                                 div.style.wordWrap = 'break-word';
                                 
                                  table = document.createElement('table');
								  table.style.width = '800px';
								  table.style.height = '24px';
								  table.cellPadding = 0;
								  table.cellSpacing = 0;
								  div.appendChild(table);
								  
								  tr = table.insertRow(-1);
								  td = tr.insertCell(-1);
								  td.style.height = '24px';
								  td.style.textAlign = 'center';
								  td.style.fontWeight = 'bold';
								  td.style.fontSize = '13px';
								  td.style.verticalAlign = 'middle';
								  
								  tr = table.insertRow(-1);
								  td = tr.insertCell(-1);
								  td.style.height = '24px';
								  td.style.verticalAlign = 'middle';

								  
								  tr = table.insertRow(-1);
								  td = tr.insertCell(-1);
								  td.style.width = '800px';
								  td.align = 'center';
								  var contentMiddle = document.createElement('table');
								  contentMiddle.style.backgroundColor = '#ebebe3';
								  contentMiddle.style.borderBottom = 'solid 1px #ccc';
								  contentMiddle.style.width = '800px';
								  contentMiddle.cellPadding = 0;
								  contentMiddle.cellSpacing = 0;
								  td.appendChild(contentMiddle);
								  
								  var ctr = contentMiddle.insertRow(-1);
								  ctd = ctr.insertCell(-1);
								  var itable = document.createElement('table');
								  itable.style.width = '800px';
								  itable.cellPadding = 0;
								  itable.cellSpacing = 0;
								  itable.style.borderTop = 'solid 1px #b4b4b4';
								  itable.style.borderLeft = 'solid 1px #b4b4b4';
								  ctd.appendChild(itable);
								  
								  itr = itable.insertRow(-1);
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '80px';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.height = '25px';
								  itd.style.color = '#333';
								  itd.style.textAlign = 'center';
								  itd.style.backgroundColor = '#ddd';
								  itd.appendChild(document.createTextNode('Date'));
								  
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '65px';
								  itd.style.color = '#333';
								  itd.style.textAlign = 'left';
								  itd.style.paddingLeft = '15px';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.backgroundColor = '#ddd';
								  itd.appendChild(document.createTextNode('Operator'));
								  
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '150px';
								  itd.style.paddingLeft = '15px';
								  itd.style.textAlign = 'left';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.color = '#333';
								  itd.style.backgroundColor = '#ddd';
								  itd.appendChild(document.createTextNode('TO'));		
								  
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '50px';
								  itd.style.paddingLeft = '15px';
								  itd.style.textAlign = 'left';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.color = '#333';
								  itd.style.backgroundColor = '#ddd';
								  itd.appendChild(document.createTextNode('Subject'));									  						  
								  
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '225px';
								  itd.style.paddingLeft = '15px';
								  itd.style.textAlign = 'left';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.color = '#333';
								  itd.style.backgroundColor = '#ddd';
								  itd.appendChild(document.createTextNode('Content'));
								  
								  
								  if(this._edata.length == 0){
								  itr = itable.insertRow(-1);
								  itd = itr.insertCell(-1);
								  itd.colSpan=6;
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '80px';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.height = '25px';
								  itd.style.color = '#333';
								  itd.style.textAlign = 'center';
								  itd.style.backgroundColor = '#ebebe3';
								  itd.appendChild(document.createTextNode('N/A'));
								  
								  }
								  
								  
								  for(var i=0;i<this._edata.length;i++){
								     var em = this._edata[i];
                                     //console.log(em);
								  
								  itr = itable.insertRow(-1);
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '80px';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.height = '25px';
								  itd.style.color = '#333';
								  itd.style.textAlign = 'center';
								  //itd.style.backgroundColor = '#ddd';
								  itd.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
								  itd.appendChild(document.createTextNode(SimpleDate.format(em.createdDate)));
								  
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '65px';
								  itd.style.color = '#333';
								  itd.style.textAlign = 'left';
								  itd.style.paddingLeft = '15px';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  //itd.style.backgroundColor = '#ddd';
								  itd.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
								  itd.appendChild(document.createTextNode(em.account));

								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '150px';
								  itd.style.paddingLeft = '15px';
								  itd.style.textAlign = 'left';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.color = '#333';
								  //itd.style.backgroundColor = '#ddd';
								  itd.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
								  itd.appendChild(document.createTextNode(em.emailto));
								  
								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '50px';
								  itd.style.paddingLeft = '15px';
								  itd.style.textAlign = 'left';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.color = '#333';
								  //itd.style.backgroundColor = '#ddd';
								  itd.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
								  itd.appendChild(document.createTextNode(em.subject));

								  itd = itr.insertCell(-1);
								  itd.style.borderRight = 'solid 1px #b4b4b4';
								  itd.style.borderBottom = 'solid 1px #b4b4b4';
								  itd.style.width = '225px';
								  itd.style.paddingLeft = '15px';
								  itd.style.textAlign = 'left';
								  itd.style.fontWeight = 'bold';
								  itd.style.fontSize = '12px';
								  itd.style.color = '#333';
								  //itd.style.backgroundColor = '#ddd';
								  itd.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
								  
						        itd.appendChild(document.createTextNode((em.bodytext.length > 8) ? em.bodytext.substring(0, 8) + '...' : em.bodytext));
						        var a = document.createElement('a');
						        a.href = '#';
						        a.appendChild(document.createTextNode('All'));
						        a._em = em;
						        a.onclick = function() { 
						                                 _popupBox21 = new PopupBox2();
						                                 func1 = function() { _popupBox21._close(); };
						                                 var pos = DOMUtils.findPos(this);
						                                 var div = document.createElement('div');
						                                 div.style.verticalAlign = 'top';
						                                 div.style.width = '420px';
						                                 div.style.color = '#ff0000';
						                                 div.style.textAlign = 'left';
						                                 div.style.padding = '4px 0 0 10px';
						                                 div.style.wordWrap = 'break-word';
						                                 div.appendChild(MiscUtils.span('\n' + this._em.bodytext));
						                                 MiscUtils.dialog(_popupBox21, pos, div, func1, null, {t: 'Content', width: 460, height: 100});
						                                 return false;
						                               };
						        itd.appendChild(a);								  
								  
								  //itd.appendChild(document.createTextNode(em.bodytext));
								  
								  
								  }
                                 
                                 //var cdate = SimpleDate.format(this._onotecalcel.canceldate);
                                 MiscUtils.dialog(_self._popupBox2, pos, div, func1, null, {t: 'Email History', width: 820, height: 50});
                                 return false;
                               };
        this._gui.order.enum.appendChild(a);  

  //this._gui.order.enum.innerHTML='99';
  /*re-email 结束*/                                                        							
  /* 初始化Customer的Order */
  if (this._customer.orders.length == 0) {
    var o = v1myorder.instance();
    o.createdDate = this._now;
    o.flag = DlmanageUtils.flag(_self._customer, Constant.ORDER_TYPE_WEDDING);
    o.type = Constant.ORDER_TYPE_WEDDING;
    o.date = null;
    this._customer.orders[0] = o;
    
    var produce = Produce.instance();
    produce.branch = '<?php echo ((is_array($_tmp=@BRANCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
';
    produce.host = 'http://<?php echo ((is_array($_tmp=@DOMAIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
<?php echo ((is_array($_tmp=@PATH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
';
    produce.title = 'Pre Con';
    produce.when = 0;
    produce.orderTrackId = o.trackId;
    produce.pi_trackId = MiscUtils.unique();
    produce.pi_model = '<?php echo ((is_array($_tmp=@MODEL_NAME_PRECON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
';
    produce.v2_notes = [];
    this._produces[this._produces.length] = produce;
  }
  /* 初始化页面的OrderTrackId */
  MiscUtils.sort(this._customer.orders, ['finished']);
  this._orderTrackId = (this._orderTrackId) ? this._orderTrackId : this._customer.orders[0].trackId;
  
  /* 显示Customer的Id */
  this._gui.customerNo.appendChild(document.createTextNode(DlmanageUtils.customerId(this._customerId)));
  
  /* Cancel Customer */
  if (this._customer.cancelled == 0) {
    this._gui.cancelCustomer.style.display = 'inline';
  } else {
    this._gui.cancelCustomer.style.display = 'none';
    this._gui.cancelReason.style.padding = ' 20px 0 0 20px';
    var div = document.createElement('div');
    div.style.fontWeight = 'bold';
    div.style.margin = '0 0 10px 0';
    div.appendChild(document.createTextNode('Cancel Reason (written by ' + this._customer.cancelledOperator + ' on ' + SimpleDate.format(this._customer.cancelledDate) + ')'));
    this._gui.cancelReason.appendChild(div);
    this._gui.cancelReason.appendChild(MiscUtils.span(this._customer.cancelledMessage));
  }
  this._gui.cancelCustomer.onclick = function() { var pos = DOMUtils.findPos(this);
                                                  var div = document.createElement('div');
                                                  var func1 = function() { _self._customer.cancelled = 1;
                                                                           _self._customer.cancelledOperator = _self._operator.account;
                                                                           _self._customer.cancelledDate = _self._now;
                                                                           _self._customer.cancelledMessage = _self._customer._text;
                                                                           for (var i = 0, il = _self._customer.orders.length; i < il; i++) {
                                                                             var order = _self._customer.orders[i];
                                                                             order.disposalstatus = 1;
                                                                             order.disposalMessage = _self._customer.cancelledMessage;
                                                                             order.disposaldate = _self._now;
                                                                             order.disposaluserAccount = _self._operator.account;
                                                                             
                                                                             var produces = MiscUtils.find(_self._produces, [{ attrs: ['orderTrackId'], value: order.trackId }, { attrs: ['_deleted'], value: undefined }]);
                                                                             for (var j = 0, jl = produces.length; j < jl; j++) {
                                                                               var p = produces[j];
                                                                               p.deadline = null;
                                                                               p.cancelled = 1;
                                                                             }
                                                                             DlmanageUtils.submit(produces, function() {  }, pos);
                                                                             if (i == _self._customer.orders.length - 1) {
                                                                               new RequestUtils()._mwrite('v1customer', [_self._customer], [], function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                                                                                                                           location.href = '?p=pageasst&t=pagecustomers&m=' + JSON.stringify({a:2, b:1});
                                                                                                                                                         } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                                                                                                                           location.href = '?p=pageserv&t=pagecustomers&m=' + JSON.stringify({a:2, b:1});
                                                                                                                                                         } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                                                                                                                           location.href = '?p=pageadmin&t=pagecustomers&m=' + JSON.stringify({a:2, b:1});
                                                                                                                                                         } else {
                                                                                                                                                           location.href = '?p=pagemanager&t=pagecustomers&m=' + JSON.stringify({a:2, b:1});
                                                                                                                                                         }
                                                                                                                                                       }, {pos: pos});
                                                                             }
                                                                           }
                                                                           _self._popupBox2._close();
                                                                         };
                                                  var func2 = function() { _self._popupBox2._close(); };
                                                  MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                                                  new DialogInput(div, _self._customer, { title: '' });
                                                };
  
  /* 显示Customer的联系方式 */
  this._gui.customer.bridename.value = this._customer.bridename;
  this._gui.customer.brideaddrLn1.value = this._customer.brideaddrLn1;
  this._gui.customer.brideaddrLn2.value = this._customer.brideaddrLn2;
  this._gui.customer.brideaddrLn3.value = this._customer.brideaddrLn3;
  this._gui.customer.brideaddrLn4.value = this._customer.brideaddrLn4;

  this._gui.customer.bridephone.value = this._customer.bridephone;
  this._gui.customer.bridemobile.value = this._customer.bridemobile;
  this._gui.customer.brideemail.value = this._customer.brideemail;
  this._gui.customer.groomname.value = this._customer.groomname;
  this._gui.customer.groomaddrLn1.value = this._customer.groomaddrLn1;
  this._gui.customer.groomaddrLn2.value = this._customer.groomaddrLn2;
  this._gui.customer.groomaddrLn3.value = this._customer.groomaddrLn3;
  this._gui.customer.groomaddrLn4.value = this._customer.groomaddrLn4;

  this._gui.customer.groomphone.value = this._customer.groomphone;
  this._gui.customer.groommobile.value = this._customer.groommobile;
  this._gui.customer.groomemail.value = this._customer.groomemail;
  this._gui.customer.pwd.value = this._customer.password;
  /*this._gui.officeNote.value = this._customer.note;*/
  
  table = document.createElement('table');
  table.cellPadding = 0;
  table.cellSpacing = 0;
  table.style.borderTop  = 'solid 1px #7a5052';
  table.style.borderLeft = 'solid 1px #7a5052';
  this._gui.oNote.appendChild(table);
  
  
    tr = table.insertRow(-1);
    tr.style.backgroundColor = '#7a5052';
    
    td = tr.insertCell(-1);
    td.style.borderRight  = 'solid 1px #fff';
    td.style.width = '104px';
    td.style.height = '24px';
    td.style.fontWeight = 'bold';
    td.style.fontSize = '9pt';
    td.style.color = 'white';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';    
    td.appendChild(document.createTextNode('Name'));  
    
    td = tr.insertCell(-1);
    td.style.borderRight  = 'solid 1px #fff';
    td.style.width = '104px';
    td.style.height = '24px';
    td.style.fontWeight = 'bold';
    td.style.fontSize = '9pt';
    td.style.color = 'white';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';  
    td.appendChild(document.createTextNode('Time'));  
    
    td = tr.insertCell(-1);
    td.style.borderRight  = 'solid 1px #fff';
    td.style.width = '790px';
    td.style.height = '24px';
    td.style.fontWeight = 'bold';
    td.style.fontSize = '9pt';
    td.style.color = 'white';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';  
    td.appendChild(document.createTextNode('contents'));   
    
    td = tr.insertCell(-1);
    td.style.borderRight  = 'solid 1px #fff';
    td.style.width = '204px';
    td.style.height = '24px';
    td.style.fontWeight = 'bold';
    td.style.fontSize = '9pt';
    td.style.color = 'white';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';    
    td.appendChild(document.createTextNode(''));          
    
    
  for (var i = 0, il = this._customer.onote.length; i < il; i++) {
  var cuson = this._customer.onote[i];
  
    tr = table.insertRow(-1);
    tr.style.backgroundColor = (tr.rowIndex % 2 != 0) ? '#fff' : '#faf9f4';
    
    td = tr.insertCell(-1);
    
    if (cuson.status == 1) {
      td.style.textDecoration = 'line-through';
    }    
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.width = '104px';
    td.style.height = '24px';
    td.style.fontSize = '9pt';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';    
    td.appendChild(document.createTextNode(cuson.Operator));  
    
    td = tr.insertCell(-1);
    if (cuson.status == 1) {
      td.style.textDecoration = 'line-through';
    }      
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.width = '104px';
    td.style.height = '24px';
    td.style.fontSize = '9pt';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';  
    td.appendChild(document.createTextNode(SimpleDate.format(cuson.date)));  
    
    td = tr.insertCell(-1);
    if (cuson.status == 1) {
      td.style.textDecoration = 'line-through';
    }      
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.width = '790px';
    td.style.height = '24px';
    td.style.fontSize = '9pt';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';  
    td.appendChild(document.createTextNode(cuson.note));   
             
  
    td = tr.insertCell(-1);
    
    if (cuson.status == 1) {
         td.appendChild(document.createTextNode((cuson.message.length > 8) ? cuson.message.substring(0, 8) + '...' : cuson.message));
        var a = document.createElement('a');
        a.href = '#';
        a.appendChild(document.createTextNode('All'));
        a._onotecalcel = cuson;
        a.onclick = function() { func1 = function() { _self._popupBox2._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.style.verticalAlign = 'top';
                                 div.style.width = '420px';
                                 div.style.color = '#ff0000';
                                 div.style.textAlign = 'left';
                                 div.style.padding = '4px 0 0 10px';
                                 div.style.wordWrap = 'break-word';
                                 div.appendChild(MiscUtils.span('\n' + this._onotecalcel.message));
                                 var cdate = SimpleDate.format(this._onotecalcel.canceldate);
                                 MiscUtils.dialog(_self._popupBox2, pos, div, func1, null, {t: 'Cancel Office Note Reason (' + this._onotecalcel.cancelop + ', ' + cdate + ')', width: 460, height: 100});
                                 return false;
                               };
        td.appendChild(a);     
    }else{
      a = document.createElement('img');
      a.src = 'images/common/delete.png';
      a.style.cursor = 'pointer';
      a._onotecalcel = cuson;
        a.onclick = function() {  var pos = DOMUtils.findPos(this);
                               var div = document.createElement('div');
                               
                               var oNote =[] ;
                               var _onotecalcel = this._onotecalcel
                               var func1 = function() { 
                                                        if(oNote._text == '')
                                                        {
                                                           window.alert('CAN NOT BE EMPTY');
                                                           return ;
                                                        }
                                                        var cusnote = {};
                                                        cusnote.note = oNote._text;
                                                        cusnote.Operator = _self._operator.account;
                                                        cusnote.date = _self._now;
                                                        cusnote.customerid = _self._customer.id;
                                                        cusnote.id = _onotecalcel.id;
                                                        
                                                        //function() { _self._retrieveCustomer.call(_self); }
                                                        new RequestUtils()._mwrite('v1office', [cusnote], [],function() { _self._retrieveCustomer.call(_self); } , { pos: pos });
                                                        _self._popupBox2._close();
                                                      };
                               var func2 = function() { _self._popupBox2._close(); };
                               MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Office Note'});
                               new DialogInput(div, oNote, { title: '' });
                               return false;
                               };
     
      td.appendChild(a);    
    
    }    
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.width = '204px';
    td.style.height = '24px';
    td.style.fontSize = '9pt';
    td.style.padding = '0 0 0 14px';
    td.style.textAlign = 'left';
    td.style.verticalAlign = 'middle';       
    
   }
  
    tr = table.insertRow(-1);
   
    td = tr.insertCell(-1);
    td.style.height = '12px';
    
        a = document.createElement('img');
        a.src = 'images/buttons/add1.png';
        a.onmouseover = function(){this.src = 'images/buttons/add1_h.png';};
        a.onmouseout = function(){this.src = 'images/buttons/add1.png';};
        
        a.onclick = function() {  var pos = DOMUtils.findPos(this);
                               var div = document.createElement('div');
                               
                               var oNote =[] ;
                               var func1 = function() { 
                                                        if(oNote._text == '')
                                                        {
                                                           window.alert('CAN NOT BE EMPTY');
                                                           return ;
                                                        }
                                                        var cusnote = {};
                                                        cusnote.note = oNote._text;
                                                        cusnote.Operator = _self._operator.account;
                                                        cusnote.date = _self._now;
                                                        cusnote.customerid = _self._customer.id;
                                                        
                                                        //function() { _self._retrieveCustomer.call(_self); }
                                                        new RequestUtils()._mwrite('v1office', [cusnote], [],function() { _self._retrieveCustomer.call(_self); } , { pos: pos });
                                                        _self._popupBox2._close();
                                                      };
                               var func2 = function() { _self._popupBox2._close(); };
                               MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Office Note'});
                               new DialogInput(div, oNote, { title: '' });
                               return false;
                               };
        td.appendChild(a);   
        
        
  
   /* tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '12px';

    td.appendChild(document.createTextNode(this._customer.note));*/
 
    
      
  this._gui.reminderNote.value = this._customer.reminderNote;
  this._gui.reminderNote.onblur = function(){_self._gui.reminderNote.value = MiscUtils.toUpper(this.value,'gg') ; _self._customer.reminderNote = MiscUtils.toUpper(this.value,'gg');} ;
  this._gui.customer.bridename.onblur = function() { _self._gui.customer.bridename.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideaddrLn1.onblur = function() {  _self._gui.customer.brideaddrLn1.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideaddrLn2.onblur = function() { _self._gui.customer.brideaddrLn2.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideaddrLn3.onblur = function() { _self._gui.customer.brideaddrLn3.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideaddrLn4.onblur = function() { _self._gui.customer.brideaddrLn4.value = MiscUtils.toUpper(this.value,'g'); }; 
  this._gui.customer.bridephone.onblur = function() { _self._gui.customer.bridephone.value = MiscUtils.toUpper(this.value,'g'); };  
  this._gui.customer.bridemobile.onblur = function() { _self._gui.customer.bridemobile.value = MiscUtils.toUpper(this.value,'g'); };  

  this._gui.customer.groomname.onblur = function() { _self._gui.customer.groomname.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn1.onblur = function() {  _self._gui.customer.groomaddrLn1.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn2.onblur = function() { _self._gui.customer.groomaddrLn2.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn3.onblur = function() { _self._gui.customer.groomaddrLn3.value = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn4.onblur = function() { _self._gui.customer.groomaddrLn4.value = MiscUtils.toUpper(this.value,'g'); }; 
  this._gui.customer.groomphone.onblur = function() { _self._gui.customer.groomphone.value = MiscUtils.toUpper(this.value,'g'); };  
  this._gui.customer.groommobile.onblur = function() { _self._gui.customer.groommobile.value = MiscUtils.toUpper(this.value,'g'); };      
  
  /* 设置Customer的联系方式Event */
  this._gui.customer.bridename.onchange = function() { _self._customer.bridename = MiscUtils.toUpper(this.value,'g'); };
 
  this._gui.customer.brideaddrLn1.onchange = function() { _self._customer.brideaddrLn1 = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideaddrLn2.onchange = function() { _self._customer.brideaddrLn2 = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideaddrLn3.onchange = function() { _self._customer.brideaddrLn3 = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideaddrLn4.onchange = function() { _self._customer.brideaddrLn4 = MiscUtils.toUpper(this.value,'g'); };
  

  
  this._gui.customer.bridephone.onchange = function() { _self._customer.bridephone = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.bridemobile.onchange = function() { _self._customer.bridemobile = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.brideemail.onchange = function() { _self._customer.brideemail = this.value; };
  this._gui.customer.groomname.onchange = function() { _self._customer.groomname = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn1.onchange = function() { _self._customer.groomaddrLn1 = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn2.onchange = function() { _self._customer.groomaddrLn2 =MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn3.onchange = function() { _self._customer.groomaddrLn3 = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomaddrLn4.onchange = function() { _self._customer.groomaddrLn4 = MiscUtils.toUpper(this.value,'g'); };

  this._gui.customer.groomphone.onchange = function() { _self._customer.groomphone = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groommobile.onchange = function() { _self._customer.groommobile = MiscUtils.toUpper(this.value,'g'); };
  this._gui.customer.groomemail.onchange = function() { _self._customer.groomemail = this.value; };
  //this._gui.officeNote.onchange = function() { _self._customer.note = this.value; };
  this._gui.reminderNote.onchange = function() { _self._customer.reminderNote = this.value; };
  /* 显示Source等信息 */
  this._gui.customer.source.name.options[this._gui.customer.source.name.options.length] = new Option('');
  for (var i = 0, il = this._sources.length; i < il; i++) {
    var source = this._sources[i];
    var option = new Option(source.name);
    this._gui.customer.source.name.options[this._gui.customer.source.name.options.length] = option;
    if (option.text == this._customer.source){
      this._gui.customer.source.name.selectedIndex = this._gui.customer.source.name.options.length - 1;
    }
  }
  this._gui.customer.source2.name.options[this._gui.customer.source2.name.options.length] = new Option('');
  for (var i = 0, il = this._sources.length; i < il; i++) {
    var source = this._sources[i];
    var option = new Option(source.name);
    this._gui.customer.source2.name.options[this._gui.customer.source2.name.options.length] = option;
    if (option.text == this._customer.source2){
      this._gui.customer.source2.name.selectedIndex = this._gui.customer.source2.name.options.length - 1;
    }
  }


  this._gui.customer.reception.name.options[this._gui.customer.reception.name.options.length] = new Option('');
  for (var i = 0, il = this._receptions.length; i < il; i++) {
    var reception = this._receptions[i];
    var option = new Option(reception.name);
    this._gui.customer.reception.name.options[this._gui.customer.reception.name.options.length] = option;
    if (option.text == this._customer.reception){
      this._gui.customer.reception.name.selectedIndex = this._gui.customer.reception.name.options.length - 1;
    }
  }

  this._gui.customer.reception2.name.options[this._gui.customer.reception2.name.options.length] = new Option('');
  for (var i = 0, il = this._receptions.length; i < il; i++) {
    var reception = this._receptions[i];
    var option = new Option(reception.name);
    this._gui.customer.reception2.name.options[this._gui.customer.reception2.name.options.length] = option;
    if (option.text == this._customer.reception2){
      this._gui.customer.reception2.name.selectedIndex = this._gui.customer.reception2.name.options.length - 1;
    }
  }

  this._gui.customer.cultural.name.options[this._gui.customer.cultural.name.options.length] = new Option('');
  for (var i = 0, il = this._cultures.length; i < il; i++) {
    var culture = this._cultures[i];
    var option = new Option(culture.name);
    this._gui.customer.cultural.name.options[this._gui.customer.cultural.name.options.length] = option;
    if (option.text == this._customer.culture){
      this._gui.customer.cultural.name.selectedIndex = this._gui.customer.cultural.name.options.length - 1;
    }
  }
  this._gui.customer.cultural2.name.options[this._gui.customer.cultural2.name.options.length] = new Option('');
  for (var i = 0, il = this._cultures.length; i < il; i++) {
    var culture = this._cultures[i];
    var option = new Option(culture.name);
    this._gui.customer.cultural2.name.options[this._gui.customer.cultural2.name.options.length] = option;
    if (option.text == this._customer.culture2){
      this._gui.customer.cultural2.name.selectedIndex = this._gui.customer.cultural2.name.options.length - 1;
    }
  }
  this._gui.customer.ceremony.name.options[this._gui.customer.ceremony.name.options.length] = new Option('');
  for (var i = 0, il = this._ceremonys.length; i < il; i++) {
    var ceremony = this._ceremonys[i];
    var option = new Option(ceremony.name);
    this._gui.customer.ceremony.name.options[this._gui.customer.ceremony.name.options.length] = option;
    if (option.text == this._customer.ceremony){
      this._gui.customer.ceremony.name.selectedIndex = this._gui.customer.ceremony.name.options.length - 1;
    }
  }

  this._gui.customer.ceremony2.name.options[this._gui.customer.ceremony2.name.options.length] = new Option('');
  for (var i = 0, il = this._ceremonys.length; i < il; i++) {
    var ceremony = this._ceremonys[i];
    var option = new Option(ceremony.name);
    this._gui.customer.ceremony2.name.options[this._gui.customer.ceremony2.name.options.length] = option;
    if (option.text == this._customer.ceremony2){
      this._gui.customer.ceremony2.name.selectedIndex = this._gui.customer.ceremony2.name.options.length - 1;
    }
  }
  
  
  /* 设置Source等信息Event */
  if (this._sources.length > 0) {
    this._customer.source = this._gui.customer.source.name.options[this._gui.customer.source.name.selectedIndex].text;
    this._gui.customer.source.name.onchange = function() { _self._customer.source = this.options[this.selectedIndex].text; };

    this._customer.source2 = this._gui.customer.source2.name.options[this._gui.customer.source2.name.selectedIndex].text;
    this._gui.customer.source2.name.onchange = function() { _self._customer.source2 = this.options[this.selectedIndex].text; }; 
  }
  
  
  
  
  if (this._receptions.length > 0) {
    this._customer.reception = this._gui.customer.reception.name.options[this._gui.customer.reception.name.selectedIndex].text;
    this._gui.customer.reception.name.onchange = function() { _self._customer.reception = this.options[this.selectedIndex].text; };

    this._customer.reception2 = this._gui.customer.reception2.name.options[this._gui.customer.reception2.name.selectedIndex].text;
    this._gui.customer.reception2.name.onchange = function() { _self._customer.reception2 = this.options[this.selectedIndex].text; };
  }
  if (this._cultures.length > 0) {
    this._customer.culture = this._gui.customer.cultural.name.options[this._gui.customer.cultural.name.selectedIndex].text;
    this._gui.customer.cultural.name.onchange = function() { _self._customer.culture = this.options[this.selectedIndex].text; };
  }
  if (this._cultures.length > 0) {
    this._customer.culture2 = this._gui.customer.cultural2.name.options[this._gui.customer.cultural2.name.selectedIndex].text;
    this._gui.customer.cultural2.name.onchange = function() { _self._customer.culture2 = this.options[this.selectedIndex].text; };
  }
  if (this._ceremonys.length > 0) {
    this._customer.ceremony = this._gui.customer.ceremony.name.options[this._gui.customer.ceremony.name.selectedIndex].text;
    this._gui.customer.ceremony.name.onchange = function() { _self._customer.ceremony = this.options[this.selectedIndex].text; };

    this._customer.ceremony2 = this._gui.customer.ceremony2.name.options[this._gui.customer.ceremony2.name.selectedIndex].text;
    this._gui.customer.ceremony2.name.onchange = function() { _self._customer.ceremony2 = this.options[this.selectedIndex].text; };
  }
  /* 添加Source等信息 */
  this._gui.customer.source.add.onclick = function() { var object = ISource.instance();
                                                       var div = document.createElement('div');
                                                       var func1 = function() { _self._popupBox._close();
                                                                                _self._customer.source = object.name;
                                                                                new RequestUtils()._mwrite('isource', [object], [], function() { _self._retrieveSources.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.source.add) });
                                                                              };
                                                       var func2 = function() { _self._popupBox._close();
                                                                              };
                                                       MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                       new DialogIObject(div, object, { name: 'isource', title: 'Sources',php: 'customphp/mysqlread.php' });
                                                     };

  this._gui.customer.source2.add.onclick = function() { var object = ISource.instance();
                                                       var div = document.createElement('div');
                                                       var func1 = function() { _self._popupBox._close();
                                                                                _self._customer.source2 = object.name;
                                                                                new RequestUtils()._mwrite('isource', [object], [], function() { _self._retrieveSources.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.source.add) });
                                                                              };
                                                       var func2 = function() { _self._popupBox._close();
                                                                              };
                                                       MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                       new DialogIObject(div, object, { name: 'isource', title: 'Sources',php: 'customphp/mysqlread.php' });
                                                     };

  this._gui.customer.reception.add.onclick = function() { var object = IReception.instance();
                                                          var div = document.createElement('div');
                                                          var func1 = function() { _self._popupBox._close();
                                                                                   _self._customer.reception = object.name;
                                                                                   new RequestUtils()._mwrite('ireception', [object], [], function() { _self._retrieveReceptions.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.reception.add) });
                                                                                 };
                                                          var func2 = function() { _self._popupBox._close();
                                                                                 };
                                                          MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                          new DialogIObject(div, object, { name: 'ireception', title: 'Reception Locations', php: 'customphp/mysqlread.php' });
                                                        };

  this._gui.customer.reception2.add.onclick = function() { var object = IReception.instance();
                                                          var div = document.createElement('div');
                                                          var func1 = function() { _self._popupBox._close();
                                                                                   _self._customer.reception2 = object.name;
                                                                                   new RequestUtils()._mwrite('ireception', [object], [], function() { _self._retrieveReceptions.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.reception.add) });
                                                                                 };
                                                          var func2 = function() { _self._popupBox._close();
                                                                                 };
                                                          MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                          new DialogIObject(div, object, { name: 'ireception', title: 'Reception Locations', php: 'customphp/mysqlread.php' });
                                                        };

  this._gui.customer.cultural.add.onclick = function() { var object = ICulture.instance();
                                                         var div = document.createElement('div');
                                                         var func1 = function() { _self._popupBox._close();
                                                                                  _self._customer.culture = object.name;
                                                                                  new RequestUtils()._mwrite('iculture', [object], [], function() { _self._retrieveCultures.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.cultural.add) });
                                                                                };
                                                         var func2 = function() { _self._popupBox._close();
                                                                                };
                                                         MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                         new DialogIObject(div, object, { name: 'iculture', title: 'Cultural Backgrounds', php: 'customphp/mysqlread.php' });
                                                       };
  this._gui.customer.cultural2.add.onclick = function() { var object = ICulture.instance();
                                                         var div = document.createElement('div');
                                                         var func1 = function() { _self._popupBox._close();
                                                                                  _self._customer.culture2 = object.name;
                                                                                  new RequestUtils()._mwrite('iculture', [object], [], function() { _self._retrieveCultures.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.cultural.add) });
                                                                                };
                                                         var func2 = function() { _self._popupBox._close();
                                                                                };
                                                         MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                         new DialogIObject(div, object, { name: 'iculture', title: 'Cultural Backgrounds', php: 'customphp/mysqlread.php' });
                                                       };
  this._gui.customer.ceremony.add.onclick = function() { var object = ICeremony.instance();
                                                         var div = document.createElement('div');
                                                         var func1 = function() { _self._popupBox._close();
                                                                                  _self._customer.ceremony = object.name;
                                                                                  new RequestUtils()._mwrite('iceremony', [object], [], function() { _self._retrieveCeremonys.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.ceremony.add) });
                                                                                };
                                                         var func2 = function() { _self._popupBox._close();
                                                                                };
                                                         MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                         new DialogIObject(div, object, { name: 'iceremony', title: 'Ceremony Locations', php: 'customphp/mysqlread.php' });
                                                       };

  this._gui.customer.ceremony2.add.onclick = function() { var object = ICeremony.instance();
                                                         var div = document.createElement('div');
                                                         var func1 = function() { _self._popupBox._close();
                                                                                  _self._customer.ceremony2 = object.name;
                                                                                  new RequestUtils()._mwrite('iceremony', [object], [], function() { _self._retrieveCeremonys.call(_self); }, { pos: DOMUtils.findPos(_self._gui.customer.ceremony.add) });
                                                                                };
                                                         var func2 = function() { _self._popupBox._close();
                                                                                };
                                                         MiscUtils.dialog(_self._popupBox, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add' });
                                                         new DialogIObject(div, object, { name: 'iceremony', title: 'Ceremony Locations', php: 'customphp/mysqlread.php' });
                                                       };
  
  /* Save & Cancel */
  if (this._customerId) {
    this._gui.save.onclick = function() { var preExist = false;
                                          for (var i = 0, il = _self._customer.orders.length; i <il; i++) {
                                            var order = _self._customer.orders[i];
                                            if (order.type == '<?php echo ((is_array($_tmp=@ORDER_TYPE_PREWEDDING)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                              preExist = true;
                                            }
                                          }
                                          if ((_self._customer.culture != '' || preExist) && _self._customer.source != '') {
                                            var str = '';
                                            for (var i = 0, il = _self._customer.orders.length; i <il; i++) {
                                              var order = _self._customer.orders[i];
                                              if (!order.date) {
                                                if (order.type != '<?php echo ((is_array($_tmp=@ORDER_TYPE_ENGAGEMENT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                  str += (order.flag + ', ');
                                                }
                                              }
                                            }
                                            if (str != '') {
                                              var r = window.confirm('NO WEDDING DAY (' + str.substring(0, str.length - 2) +'), CONTINUE?');
                                              if (r) {
                                                DlmanageUtils.trimcustomer(_self._customer);
                                                var pos = DOMUtils.findPos(this);
                                                new RequestUtils()._mwrite('v1customer', [_self._customer], [], function() { location.reload(); }, {pos: pos });
                                              }
                                            } else {
                                              DlmanageUtils.trimcustomer(_self._customer);
                                              var pos = DOMUtils.findPos(this);
                                              new RequestUtils()._mwrite('v1customer', [_self._customer], [], function() { location.reload(); }, {pos: pos });
                                            }
                                          } else {
                                            if (preExist && _self._customer.source == '') {
                                              window.alert('CAN NOT BE EMPTY (Source)');
                                            } else {
                                              window.alert('CAN NOT BE EMPTY (Cultural Background, Source)');
                                            }
                                          }
                                        };
										
    this._gui.save1.onclick = function() { var preExist = false;
                                          for (var i = 0, il = _self._customer.orders.length; i <il; i++) {
                                            var order = _self._customer.orders[i];
                                            if (order.type == '<?php echo ((is_array($_tmp=@ORDER_TYPE_PREWEDDING)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                              preExist = true;
                                            }
                                          }
                                          if ((_self._customer.culture != '' || preExist) && _self._customer.source != '') {
                                            var str = '';
                                            for (var i = 0, il = _self._customer.orders.length; i <il; i++) {
                                              var order = _self._customer.orders[i];
                                              if (!order.date) {
                                                if (order.type != '<?php echo ((is_array($_tmp=@ORDER_TYPE_ENGAGEMENT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                  str += (order.flag + ', ');
                                                }
                                              }
                                            }
                                            if (str != '') {
                                              var r = window.confirm('NO WEDDING DAY (' + str.substring(0, str.length - 2) +'), CONTINUE?');
                                              if (r) {
                                                DlmanageUtils.trimcustomer(_self._customer);
                                                var pos = DOMUtils.findPos(this);
                                                new RequestUtils()._mwrite('v1customer', [_self._customer], [], function() { location.reload(); }, {pos: pos });
                                              }
                                            } else {
                                              DlmanageUtils.trimcustomer(_self._customer);
                                              var pos = DOMUtils.findPos(this);
                                              new RequestUtils()._mwrite('v1customer', [_self._customer], [], function() { location.reload(); }, {pos: pos });
                                            }
                                          } else {
                                            if (preExist && _self._customer.source == '') {
                                              window.alert('CAN NOT BE EMPTY (Source)');
                                            } else {
                                              window.alert('CAN NOT BE EMPTY (Cultural Background, Source)');
                                            }
                                          }
                                        };
										
    this._gui.cancel.onclick = function() { history.back(); };
  }
  
  this._updateOrders();
};

HandlePageCustomerOld.prototype._updateOrders = function() {
  var _self = this;
  
  this._gui.order.printOrders.style.display = 'none';
  this._gui.order.print.style.display = 'none';
  this._gui.order.modify.style.display = 'none';
  this._gui.order.finish.style.display = 'none';
  this._gui.order.cancel.style.display = 'none';
  this._gui.order.payment.print.style.display = 'none';
  
  DlmanageUtils.clear(this._gui.order);
  DlmanageUtils.clear(this._gui.payment);
  
  /* 显示订单的标签 */
  var func = function(trackId) { _self._orderTrackId = trackId; 
                                 _self._updateOrders.call(_self);
                               };
                               
  new IContainerTabOrders(this._gui.order.orderTab, this._customer.orders, { callbackFunc: func, trackId: this._orderTrackId });
  
  /* 显示所有订单的总价和打折率 */
  var total = 0;
  var original = 0;
  var received = 0;
  for (var i = 0, il = this._customer.orders.length; i < il; i++) {
    var order = this._customer.orders[i];
    if (order.disposalstatus == 0) {
      order.price = Math.max(order.price, 0);
      total += parseFloat(order.price, 10);
      original += parseFloat(DlmanageUtils.total(order), 10);
    }
    
    MiscUtils.sort(order.payments, ['id']);
    for (var j = 0, jl = order.payments.length; j < jl; j++) {
      var payment = order.payments[j];
      if (payment.cancelled == 1) {
        continue;
      }
      received += parseFloat(payment.amount);
    }
  }
  var refund = 0;
  for (var j = 0, jl = this._refunds.length; j < jl; j++) {
    var r = this._refunds[j];
    if (r.status == -1 || r.refundNo == 0) {
      continue;
    }
    refund += parseFloat(r.amount, 10);
  }
  
  total = total.toFixed(2);
  original = original.toFixed(2);
  received = received.toFixed(2);
  refund = refund.toFixed(2);
  received = (received - refund);
  this._gui.payment.price.appendChild(document.createTextNode((total > 0) ? '$' + (total * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) ).toFixed(2) + ' (Inc. ' +  '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
  if (parseFloat(total) != parseFloat(original)) {
     if(parseFloat(total) < parseFloat(original)){         
       this._gui.payment.percent.appendChild(document.createTextNode( ' '+(((original - total) / original) * 100).toFixed(1) + '% Off' ));
     }else{
       this._gui.payment.percent.appendChild(document.createTextNode( ' '+ 0 + '% Off' ));
     }
  }
  this._gui.payment.received.appendChild(document.createTextNode('$' + received.toFixed(2)));
  
  if(total > 0){
   this._gui.payment.anticipated.appendChild(document.createTextNode('$' + ((total * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) ).toFixed(2) - received).toFixed(2)));
  }else{
   this._gui.payment.anticipated.appendChild(document.createTextNode('$' + ((total * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) - received).toFixed(2)));
  }
  /* 处理订单 */
  this._updateOrder();
}; 

HandlePageCustomerOld.prototype._updateOrder = function() {
  var table, tr, td, order = DlmanageUtils.order(this._customer.orders, this._orderTrackId),_self = this;
  
  if (order.type == Constant.ORDER_TYPE_PREWEDDING || order.type == Constant.ORDER_TYPE_PORTRAIT || order.type == Constant.ORDER_TYPE_OTHER) {
    this._gui.customer.rc.style.visibility = 'hidden';
    this._gui.customer.rc2.style.visibility = 'hidden';
  } else {
    this._gui.customer.rc.style.visibility = 'visible';
    this._gui.customer.rc2.style.visibility = 'visible';
  }
  
  /* 提取所有Produces */
  var produces = MiscUtils.find(this._produces, [{ attrs: ['orderTrackId'], value: order.trackId }, { attrs: ['_deleted'], value: undefined }]);

  
  this._gui.order.printOrders.style.display = 'inline';
  this._gui.order.payment.print.style.display = 'inline';
  this._gui.order.modify.style.display = 'inline';
  
  /* 设置Print,Modify和Cancel。显示Cancel Reason（如果订单被Cancel） */
  if (order.disposalstatus == 0) {
    this._gui.order.cancel.style.display = 'inline';
    this._gui.order.print.style.display = 'inline';
  } else {
    if (this._customer.cancelled == 0) {
      this._gui.order.message.style.padding = ' 0 0 20px 20px';
      var div = document.createElement('div');
      div.style.fontWeight = 'bold';
      div.style.margin = '0 0 10px 0';
      div.appendChild(document.createTextNode('Cancel Reason (written by ' + order.disposaluserAccount + ' on ' + SimpleDate.format(SimpleDate.fromStamp(order.disposaldate)) + ')'));
      this._gui.order.message.appendChild(div);
      this._gui.order.message.appendChild(MiscUtils.span(order.disposalmessage));
    }
  }
  if ( order.disposalstatus == 1  || order.finished == 1) {//cancel or finished
    this._gui.bgcolor.style.backgroundColor = '#ddd';
    this._gui.fontColor1.style.color = '#000';
    this._gui.fontColor2.style.color = '#000';
    this._gui.fontColor3.style.color = '#000';
    this._gui.fontColor4.style.color = '#000';
    this._gui.fontColor5.style.color = '#000';
    this._gui.fontColor6.style.color = '#000';
    this._gui.fontColor7.style.color = '#000';
    this._gui.fontColor8.style.color = '#000';
    this._gui.fontColor9.style.color = '#000';
    this._gui.fontColor10.style.color = '#000';
    this._gui.fontColor11.style.color = '#000';
    this._gui.fontColor12.style.color = '#000';
    this._gui.fontColor13.style.color = '#000';
    this._gui.fontColor14.style.color = '#000';
    this._gui.fontColor15.style.color = '#000';
    this._gui.fontColor16.style.color = '#000';
    this._gui.fontColor17.style.color = '#000';
    this._gui.fontColor18.style.color = '#000';
    this._gui.fontColor19.style.color = '#000';
    this._gui.fontColor20.style.color = '#000';
    this._gui.fontColor21.style.color = '#000';
    this._gui.fontColor22.style.color = '#000';
    this._gui.fontColor23.style.color = '#000';
    this._gui.fontColor24.style.color = '#000';
    this._gui.fontColor25.style.color = '#000';
    this._gui.fontColor26.style.color = '#000';
    this._gui.fontColor27.style.color = '#000';
    this._gui.fontColor28.style.color = '#000';
    this._gui.fontColor29.style.color = '#000';
    this._gui.fontColor30.style.color = '#000';
    this._gui.fontColor31.style.color = '#000';
    this._gui.fontColor32.style.color = '#000';
    this._gui.fontColor33.style.color = '#000';
    this._gui.fontColor34.style.color = '#000';
    this._gui.fontColor35.style.color = '#000';
    this._gui.order.payment.date.disabled = true;
    this._gui.order.refund.date.disabled = true;
    this._gui.order.payment.pay1.fee.disabled = true;
    this._gui.order.payment.pay2.fee.disabled = true;
    this._gui.order.payment.pay3.fee.disabled = true;
    this._gui.order.payment.pay4.fee.disabled = true;
    this._gui.order.payment.pay1.payBtn.disabled = true;
    this._gui.order.payment.pay2.payBtn.disabled = true;
    this._gui.order.payment.pay3.payBtn.disabled = true;
    this._gui.order.payment.pay4.payBtn.disabled = true;
    this._gui.order.refund.fee.disabled = true;
    this._gui.order.refund.payBtn.disabled = true;
  } else {
    this._gui.bgcolor.style.backgroundColor = '#EBEBE3';
    this._gui.fontColor1.style.color = '#694247';
    this._gui.fontColor2.style.color = '#694247';
    this._gui.fontColor3.style.color = '#694247';
    this._gui.fontColor4.style.color = '#694247';
    this._gui.fontColor5.style.color = '#694247';
    this._gui.fontColor6.style.color = '#694247';
    this._gui.fontColor7.style.color = '#694247';
    this._gui.fontColor8.style.color = '#694247';
    this._gui.fontColor9.style.color = '#694247';
    this._gui.fontColor10.style.color = '#694247';
    this._gui.fontColor11.style.color = '#694247';
    this._gui.fontColor12.style.color = '#694247';
    this._gui.fontColor13.style.color = '#694247';
    this._gui.fontColor14.style.color = '#694247';
    this._gui.fontColor15.style.color = '#694247';
    this._gui.fontColor16.style.color = '#694247';
    this._gui.fontColor17.style.color = '#694247';
    this._gui.fontColor18.style.color = '#694247';
    this._gui.fontColor19.style.color = '#694247';
    this._gui.fontColor20.style.color = '#694247';
    this._gui.fontColor21.style.color = '#694247';
    this._gui.fontColor22.style.color = '#694247';
    this._gui.fontColor23.style.color = '#694247';
    this._gui.fontColor24.style.color = '#694247';
    this._gui.fontColor25.style.color = '#694247';
    this._gui.fontColor26.style.color = '#694247';
    this._gui.fontColor27.style.color = '#694247';
    this._gui.fontColor28.style.color = '#694247';
    this._gui.fontColor29.style.color = '#694247';
    this._gui.fontColor30.style.color = '#694247';
    this._gui.fontColor31.style.color = '#694247';
    this._gui.fontColor32.style.color = '#694247';
    this._gui.fontColor33.style.color = '#694247';
    this._gui.fontColor34.style.color = '#694247';
    this._gui.fontColor35.style.color = '#694247';
    this._gui.order.payment.date.disabled = false;
    this._gui.order.refund.date.disabled = false;
    this._gui.order.payment.pay1.fee.disabled = false;
    this._gui.order.payment.pay2.fee.disabled = false;
    this._gui.order.payment.pay3.fee.disabled = false;
    this._gui.order.payment.pay4.fee.disabled = false;
    this._gui.order.payment.pay1.payBtn.disabled = false;
    this._gui.order.payment.pay2.payBtn.disabled = false;
    this._gui.order.payment.pay3.payBtn.disabled = false;
    this._gui.order.payment.pay4.payBtn.disabled = false;
    this._gui.order.refund.fee.disabled = false;
    this._gui.order.refund.payBtn.disabled = false;
  }
  
  if (order.finished == 0 && order.disposalstatus == 0) {
    this._gui.order.finish.style.display = 'inline';
  }
  
  this._gui.order.modify.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                  if (order.id) {
                                                    location.href = '?p=pageasst&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: order.trackId }); 
                                                  } else {
                                                    location.href = '?p=pageasst&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id }); 
                                                  }
                                                } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                  if (order.id) {
                                                    location.href = '?p=pageserv&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: order.trackId });
                                                  } else {
                                                    location.href = '?p=pageserv&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id });
                                                  }
                                                } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                  if (order.id) {
                                                    location.href = '?p=pageadmin&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: order.trackId });
                                                  } else {
                                                    location.href = '?p=pageadmin&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id });
                                                  }
                                                } else {
                                                  if (order.id) {
                                                    location.href = '?p=pagemanager&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: order.trackId });
                                                  } else {
                                                    location.href = '?p=pagemanager&t=pagecustomer&m=' + JSON.stringify({a:2, b:1}) + '&opts=' + JSON.stringify({ id: _self._customer.id });
                                                  }
                                                }
                                              };
  
  this._trackId = [];
  for(var i = 0, il = this._customer.orders.length; i < il; i++) {
    var o = this._customer.orders[i];
    if (o.disposalstatus == 0) {
      this._trackId[this._trackId.length] = o.trackId;
    }
  }
  
  /*******************sign********************************/
    if(order.sign.length > 0)
    {
       this._gui.order.sign.style.display = 'inline';
       this._gui.order.unsign.style.display = 'none';
       
       this._gui.order.sign.onclick = function() {
           //console.log(order.id);
          window.open('sign/contractinfo.php?orderid='+order.id);
         
       };
       
    }else{
       this._gui.order.sign.style.display = 'none';
       this._gui.order.unsign.style.display = 'inline';
       this._gui.order.unsign.disabled = true;
    }
    
    
  
  /*******************sign********************************/
    
  this._gui.order.print.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                 var w = window.open('?p=pageasst&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId], type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                 w.focus();
                                               } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                 var w = window.open('?p=pageserv&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId], type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                 w.focus();
                                               } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                 var w = window.open('?p=pageadmin&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId], type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                 w.focus();
                                               } else {
                                                 var w = window.open('?p=pagemanager&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId], type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                 w.focus();
                                               }
                                             };
  this._gui.order.printOrders.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                       var w = window.open('?p=pageasst&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._trackId, type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                       w.focus();
                                                     } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                       var w = window.open('?p=pageserv&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._trackId, type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                       w.focus();
                                                     } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                       var w = window.open('?p=pageadmin&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._trackId, type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                       w.focus();
                                                     } else {
                                                       var w = window.open('?p=pagemanager&t=pagecontract' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._trackId, type: order.type }), 'Contract', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                       w.focus();
                                                     }
                                                   }; 
  
  this._gui.order.finish.onclick = function() { var r = window.confirm('ALL PROCESSES WILL BE TERMINATED, CONTINUE?');
                                                if (r) {
                                                  order.finished = 1;
                                                  var pos = DOMUtils.findPos(this);
                                                  new RequestUtils()._mwrite('v1myorder_close', [order], [], function(result, params) { var customer = (result.data.length == 1) ? result.data[0] : null; 
                                                                                                                                    var func = function(result, params) {
                                                                                                                                                         if (customer) {
                                                                                                                                                         if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                                                                                                                           location.href = '?p=pageasst&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._orderTrackId });
                                                                                                                                                         } else if ( _self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' ) {
                                                                                                                                                           location.href = '?p=pageserv&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._orderTrackId }); 
                                                                                                                                                         } else if ( _self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' ) {
                                                                                                                                                           location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._orderTrackId }); 
                                                                                                                                                         } else {
                                                                                                                                                           location.href = '?p=pagemanager&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: _self._customer.id, track: _self._orderTrackId });
                                                                                                                                                         }
                                                                                                                                                       }
                                                                                                                                                     };
                                                                                                                 for (var i = 0, il = _self._produces.length; i < il; i++) {
                                                                                                                   var tmp = _self._produces[i];
                                                                                                                   if(tmp.orderId == order.e_oid) 
                                                                                                                   {
                                                                                                                     tmp.state -= 9999;
                                                                                                                   }
                                                                                                                 }
                                                                                                                 
                                                                                                                 
                                                                                                                 DlmanageUtils.patch(_self._produces, _self._customer);
                                                                                                                 DlmanageUtils.submit(_self._produces, func, pos);
                                                                                                               }, { pos: pos });
                                                }
                                              }; 
  
  this._gui.order.cancel.onclick = function() { var pos = DOMUtils.findPos(this);
                                                var div = document.createElement('div');
                                                var func1 = function() { order.disposaldate = _self._now;
                                                                         order.disposaluserAccount = _self._operator.account;
                                                                         order.disposalstatus = true;
                                                                         order.disposalmessage = order._text;
                                                                         new RequestUtils()._mwrite('v1myorder', [order], [], function() { for (var i = 0, il = produces.length; i < il; i++) {
                                                                                                                                          var p = produces[i];
                                                                                                                                          p.deadline = null;
                                                                                                                                          p.cancelled = 1;
                                                                                                                                        }
                                                                                                                                        DlmanageUtils.submit(produces, function() { _self._retrieveCustomer.call(_self); }, pos);
                                                                                                                                      }, { pos: pos });
                                                                         _self._popupBox2._close();
                                                                       };
                                                var func2 = function() { _self._popupBox2._close(); };
                                                MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                                                new DialogInput(div, order, { title: '' });
                                              };
  
  /* 显示订单基本信息 */
  var refund = 0;
  for (var j = 0, jl = this._refunds.length; j < jl; j++) {
    var r = this._refunds[j];
    if (r.status == -1 || r.refundNo != order.id) {
      continue;
    }
    refund += parseFloat(r.amount, 10);
  }
  this._gui.order.total.appendChild(document.createTextNode(((order.price - refund) > 0) ? '$' + (order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) - refund).toFixed(2) + ' (Inc. ' +  '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));

  var total = DlmanageUtils.total(order);

  if (parseFloat(order.price) != parseFloat(total)) {
     if(parseFloat(order.price) < parseFloat(total)){
       this._gui.order.percent.appendChild(document.createTextNode( (((total - order.price) / total) * 100).toFixed(1) + '% Off' ));
     }else{
       this._gui.order.percent.appendChild(document.createTextNode( 0 + '% Off' ));
     }
  }
  this._gui.order.type.appendChild(document.createTextNode(order.type));
  this._gui.order.photoPackage.appendChild(document.createTextNode(order.photoname));
  this._gui.order.videoPackage.appendChild(document.createTextNode(order.videoname));
  
  this._gui.order.dateTitle.style.display = 'block';
  if ( order.disposalstatus == 1  || order.finished == 1) {
    this._gui.order.dateTitle.style.color = '#000';
  }else{
    this._gui.order.dateTitle.style.color = '#694247';
  }
  if (order.type != '<?php echo ((is_array($_tmp=@ORDER_TYPE_WEDDING)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
    this._gui.order.dateTitle.appendChild(document.createTextNode('Working Date'));
  } else {
    this._gui.order.dateTitle.appendChild(document.createTextNode('Wedding Date'));
  }

  this._gui.order.date.appendChild(document.createTextNode((order.date) ?  SimpleDate.format(order.date) : 'To Be Confirmed' ));
  this._gui.order.customerNote.appendChild(document.createTextNode(order.note));
  
  var op, wp, gp, pp, ap, purchase, p, a;
  /* 提取所有Precon、Music、Photographer、Videographer和Makeup流程 */
  op = MiscUtils.find(produces, [{ attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRECON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_MUSIC)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_REQUIREMENT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }], MiscUtils.disjunction);
  wp = MiscUtils.find(produces, [{ attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_PHOTOGRAPHER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_VIDEOGRAPHER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_MAKEUP)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_LIGHT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }], MiscUtils.disjunction);
  
  /* 提取所有产品流程 ,并且分类到套餐产品流程和附加产品流程 */
  gp = MiscUtils.find(produces, [{ attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_SLIDESHOWW)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_SLIDESHOW)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_SLIDESHOW_OL)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEO_BLURAY)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEODVD_BLURAY)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEO)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEODVD)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_4X6)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH_MAGAZINE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_COMMON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['pi_model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_ALBUM_DESIGN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }], MiscUtils.disjunction);
  pp = MiscUtils.find(gp, [{ attrs: ['pi_packageInc'], value: '', unequal: true }]);
  ap = MiscUtils.find(gp, [{ attrs: ['pi_packageInc'], value: '' }]);
  /* 提取所有产品 ,并且分类到套餐产品和附加产品 */
  purchases = MiscUtils.find(order.purchaseItems, [{ attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_SLIDESHOWW)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' },{ attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_SLIDESHOWW)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' },{ attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_SLIDESHOW)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_SLIDESHOW_OL)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEO_BLURAY)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEODVD_BLURAY)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEO)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_VIDEODVD)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_4X6)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH_MAGAZINE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_RETOUCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_PRODUCT_COMMON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '<?php echo ((is_array($_tmp=@MODEL_NAME_ALBUM_DESIGN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' }, { attrs: ['model'], value: '' }], MiscUtils.disjunction);
  p = MiscUtils.find(purchases, [{ attrs: ['packageInc'], value: '', unequal: true }]);
  a = MiscUtils.find(purchases, [{ attrs: ['packageInc'], value: '' }]);
  
  /* 设置流程表格 */
  new TableProduceOthers(this._gui.order.pmusic, op, { user: this._operator, date: this._now, callbackFunc: function() { _self._retrieveProduces.call(_self); }, parent: order, isfromcus: true });
  var func = function(pos) { _self._produces = null;
                             _self._customer = null;
                             _self._receptions = null;
                             _self._ceremonys = null;
                             _self._retrieveProduces.call(_self, pos); 
                             _self._retrieveCustomer.call(_self);
                             _self._retrieveReceptions.call(_self);
                             _self._retrieveCeremonys.call(_self);
                           };
  new TableProduceWorkers(this._gui.order.photoVideo, wp, { user: this._operator, date: this._now, callbackFunc: func, parent: order, isfromcus: true });
  MiscUtils.sort(pp, ['title']);
  MiscUtils.sort(ap, ['title']);
  new TableProducePurchases(this._gui.order.packageInclude, pp, { user: this._operator, date: this._now, callbackFunc: function(pos) { _self._retrieveProduces.call(_self, pos); }, rest: p, produces: this._produces, purchases: order.purchaseItems, hidePrice: true, parent: order, isfromcus: true });
  new TableProducePurchases(this._gui.order.additions, ap, { user: this._operator, date: this._now, callbackFunc: function(pos) { _self._retrieveProduces.call(_self, pos); }, rest: a, produces: this._produces, purchases: order.purchaseItems, parent: order, isfromcus: true });


  /* 显示所有产品的操作历史记录 */
  this._gui.order.branchHistory.style.display = 'block';
  this._gui.order.branchHistory.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                          var w = window.open('?p=pageasst&t=pagebranchhistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'BranchHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                          var w = window.open('?p=pageserv&t=pagebranchhistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'BranchHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                          var w = window.open('?p=pageadmin&t=pagebranchhistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'BranchHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        } else {
                                                          var w = window.open('?p=pagemanager&t=pagebranchhistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'BranchHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        }
                                                        return false;
                                                      };
  


  /* 显示所有产品流程的操作历史记录 */
  this._gui.order.produceHistory.style.display = 'block';
  this._gui.order.produceHistory.onclick = function() { if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                          var w = window.open('?p=pageasst&t=pageproducehistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'ProduceHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                          var w = window.open('?p=pageserv&t=pageproducehistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'ProduceHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                          var w = window.open('?p=pageadmin&t=pageproducehistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'ProduceHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        } else {
                                                          var w = window.open('?p=pagemanager&t=pageproducehistory' + '&opts=' + JSON.stringify({ id: _self._customer.id, track: [order.trackId]}), 'ProduceHistory', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                          w.focus();
                                                        }
                                                        return false;
                                                      };

  
  /* 设置Payment版块*/
  var total = 0;
  for (var i = 0, il = order.payments.length; i < il; i++) {
    var p = order.payments[i];
    if (p.cancelled == 1) {
      continue;
    }
    total += parseFloat(p.amount, 10);
  }
  
  var refund = 0;
  for (var j = 0, jl = this._refunds.length; j < jl; j++) {
    var r = this._refunds[j];
    if (r.status == -1 || r.refundNo != order.id) {
      continue;
    }
    refund += parseFloat(r.amount, 10);
  }
  
  total = (total - refund);
  this._gui.order.payment.price.appendChild(document.createTextNode(((order.price - refund) > 0) ? '$' + (order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) - refund).toFixed(2) + ' (Inc. ' +  '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));

  this._gui.order.payment.received.appendChild(document.createTextNode('$' + total.toFixed(2)));
  this._gui.order.payment.anticipated.appendChild(document.createTextNode('$' + ((order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) - refund).toFixed(2) - total).toFixed(2)));
  
  this._gui.order.payment.print.onclick = function() { var p = [];
                                                       for(var i = 0, il = _self._customer.orders.length; i < il; i++) {
                                                         var o = _self._customer.orders[i];
                                                         if (o.disposalstatus=='0') {
                                                           p[p.length] = o.trackId;
                                                         }
                                                       }
                                                       if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                         var w = window.open('?p=pageasst&t=pagereceipt&opts=' + JSON.stringify({ id: _self._customer.id, track: p }), 'Receipt', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                         w.focus();
                                                       } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_CUSTOMER_SERVICE)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                         var w = window.open('?p=pageserv&t=pagereceipt&opts=' + JSON.stringify({ id: _self._customer.id, track: p }), 'Receipt', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                         w.focus();
                                                       } else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                         var w = window.open('?p=pageadmin&t=pagereceipt&opts=' + JSON.stringify({ id: _self._customer.id, track: p }), 'Receipt', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                         w.focus();
                                                       } else {
                                                         var w = window.open('?p=pagemanager&t=pagereceipt&opts=' + JSON.stringify({ id: _self._customer.id, track: p }), 'Receipt', 'width=1024,height=768,scrollbars=1,location=0', true);
                                                         w.focus();
                                                       }
                                                     };
  
  this._paymentDate = this._now;
  this._gui.order.payment.date.value = SimpleDate.format(this._paymentDate);
  this._gui.order.payment.date.onclick = function() { var context = this;
                                                      _self._changeDate.call(_self, this, _self._paymentDate, function(sd) { _self._paymentDate = sd; context.focus(); }, false);
                                                    };

  var rules = DlmanageUtils.payment(order.type);
  
  if (rules[0]) {
    this._gui.order.payment.pay1.container.style.display = 'block';
    this._pay(this._gui.order.payment.pay1, 1, rules[0]);
  } else {
    this._gui.order.payment.pay1.container.style.display = 'none';
  }
  if (rules[1]) {
    this._gui.order.payment.pay2.container.style.display = 'block';
    this._pay(this._gui.order.payment.pay2, 2, rules[1]);
  } else {
    this._gui.order.payment.pay2.container.style.display = 'none';
  }
  if (rules[2]) {
    this._gui.order.payment.pay3.container.style.display = 'block';
    this._pay(this._gui.order.payment.pay3, 3, rules[2]);
  }
   else {
    this._gui.order.payment.pay3.container.style.display = 'none';
  }
  if (rules[3]) {
    this._gui.order.payment.pay4.container.style.display = 'block';
    this._pay(this._gui.order.payment.pay4, 4, rules[3]);
  } else {
    this._gui.order.payment.pay4.container.style.display = 'none';
  }
  
  this._refund(this._gui.order.refund);
};

HandlePageCustomerOld.prototype._pay = function(gui, stage, rule) {
  var table, tr, td, a, order = DlmanageUtils.order(this._customer.orders, this._orderTrackId), _self = this;
  var payment = v1payment.instance();
  payment.stage = stage;
  payment.method = '';
  payment.orderId = order.id;
  payment.orderFlag = order.flag;
  payment.customerId = this._customer.id;
  
  gui.container.style.verticalAlign = 'top';
  gui.percent.appendChild(document.createTextNode(rule.title));
  gui.fee.value = '';
  
  gui.cash.checked = false;
  gui.cheque.checked = false;
  gui.bank.checked = false;
  
  gui.cash.onclick = function() { payment.method = 'cash'; };
  gui.cheque.onclick = function() { payment.method = 'cheque'; };
  gui.bank.onclick = function() { payment.method = 'bank transfer'; };
  
  /*payment*/
  gui.payBtn.onclick = function() { if (gui.fee.value == '' || gui.fee.value == 0) {
                                      window.alert('数值不能为\'' + gui.fee.value + '\'');
                                      return;
                                    } 
                                    if (payment.method == '') {
                                      window.alert('必须选择支付方式');
                                      return;
                                    }
                                    if (!_self._paymentDate) {
                                      window.alert('必须选择支付日期');
                                      return;
                                    }
                                    if(payment.method == 'cheque')
                                    {

                                        
                                      var div = document.createElement('div');
                                      var div2 = document.createElement('div');
                                      var div3 = document.createElement('div');
                                      
                                       
                                      div2.style.marginTop = '5px';
                                      div3.style.marginTop = '5px';                                      
                                      div3.style.paddingLeft = '12px';
                                      
                                      var input = document.createElement('input');
                                      input.type='text';
                                      input.style.width = '345px';
                                      input.style.height = '30px';
                                      input.value ='';
                                  
                                    
                                  var input1 = document.createElement('input');
                                      input1.type='text';
                                      input1.style.width = '345px';
                                      input1.style.height = '30px';
                                      input1.value = '';
                                     
                                      div2.appendChild(document.createTextNode('Cheque Number '));
                                      div2.appendChild(input);
                                     
                                      div3.appendChild(document.createTextNode('Account Name  '));
                                      div3.appendChild(input1);
                                      
                                      div.appendChild(div2);
                                      div.appendChild(div3);
                                      
                                      
                                      var pos = DOMUtils.findPos(this);
                                      var pay1 = [];
                                    
                                      
                                      var func5 =function() { _self._retrieveCustomer.call(_self); };
                                      var func1 = function() { 
                                          if (input.value == '') {
                                              window.alert('请输入Cheque Number');
                                              return;
                                            }
                                          
                                          
                                          if (input1.value == '') {
                                              window.alert('请输入Account Name');
                                              return;
                                            }                                      	  
                                    	  
                                          payment.date = _self._paymentDate;
                                          payment.amount = gui.fee.value;
                                          payment.userAccount = _self._operator.account;
                                          payment.cchequenumber = input.value;
                                          payment.cAccountname = input1.value;
                                          payment.cnote = pay1._text;
                                          order.payments[order.payments.length] = payment;
                                          _popupBox2 = new PopupBox2()
                                           //var div2 = document.createElement('div');
                                           //div2.appendChild(document.createTextNode('Email Receipt ?'));
							         var pay11 = [];
                                      
                                      var _default ='Dear '+ _self._customer.bridename + ' & '+ _self._customer.groomname + ' , ' + "\n"+
                                                   "\n"+
                                                  'Please find the attached pdf file' + "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  'Kind Regards' + "\n"+
                                                  'Yours Sincerely ' + '<?php echo ((is_array($_tmp=@SHOPNAME)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' ;
                                                        
                                      var divr = document.createElement('div');
                                      var div2r = document.createElement('div');
                                      
                                       
                                      div2r.style.marginTop = '5px';
                                      
                                      var inputr = document.createElement('input');
                                      inputr.type='text';
                                      inputr.style.width = '345px';
                                      inputr.style.height = '30px';
                                      inputr.value ='Receipt for Customer '+_self._customer.id;
                                  
                                      div2r.appendChild(document.createTextNode('Subject '));
                                      div2r.appendChild(inputr);
                                      divr.appendChild(div2r);    										   
                                           
                                           func12 =function(){
                                                    var rpt = {};
                                                        rpt.id = _self._customer.id;
                                                        rpt.brideemail = _self._customer.brideemail;
                                                        rpt.groomemail = _self._customer.groomemail;
                                                        rpt.createDate = _self._now;
                                                        rpt.account = _self._operator;
														rpt.bodytext = pay11._text;
														rpt.subject = inputr.value;
														
                                                        new RequestUtils()._mwrite('receiptpdf', [rpt], [], func5, { pos: DOMUtils.findPos(this) });
                                                        _popupBox2._close();                                           
                                           }
                                           
                                                    var func11 = function(){
                                                        var func21 = function() { _popupBox2._close();func5(); };
                                                        MiscUtils.dialog(_popupBox2, pos, divr, func12, func21, {t: 'Email Receipt',ok:'Email',cancel:'No Email'});
														new DialogInput(divr, pay11, { title: '',default: _default});
                                                        
                                                    };
                                           
                                           
                                          
                                          //function() { _self._retrieveCustomer.call(_self); }
                                          new RequestUtils()._mwrite('v1payment', [order], [],func11 , { pos: pos });  
                                          _self._popupBox2._close();
                                        };  
                                        
                                        var func2 = function() { _self._popupBox2._close();func5();};
                                        MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cheque'});
                                        new DialogInput(div, pay1, { title: '' });
                                        //return false;                                        
                                      
                                    }else{
                                         var pos = DOMUtils.findPos(this);
							         var pay11 = [];
                                      
                                      var _default ='Dear '+ _self._customer.bridename + ' & '+ _self._customer.groomname + ' , ' + "\n"+
                                                   "\n"+
                                                  'Please find the attached pdf file' + "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  "\n"+
                                                  'Kind Regards' + "\n"+
                                                  'Yours Sincerely ' + '<?php echo ((is_array($_tmp=@SHOPNAME)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' ;
                                                        
                                      var divr = document.createElement('div');
                                      var div2r = document.createElement('div');
                                      
                                       
                                      div2r.style.marginTop = '5px';
                                      
                                      var inputr = document.createElement('input');
                                      inputr.type='text';
                                      inputr.style.width = '345px';
                                      inputr.style.height = '30px';
                                      inputr.value ='Receipt for Customer '+_self._customer.id;
                                  
                                      div2r.appendChild(document.createTextNode('Subject '));
                                      div2r.appendChild(inputr);
                                      divr.appendChild(div2r);                                           
                                        
                                       
                                      var func1 = function(){ _self._retrieveCustomer.call(_self);};
                                      var func11 = function(){
                                                    var rpt = {};
                                                        rpt.id = _self._customer.id;
                                                        rpt.brideemail = _self._customer.brideemail;
                                                        rpt.groomemail = _self._customer.groomemail;
                                                        rpt.createDate = _self._now;
                                                        rpt.account = _self._operator;
                                                        rpt.bodytext = pay11._text;
                                                        rpt.subject = inputr.value;  
                                                        new RequestUtils()._mwrite('receiptpdf', [rpt], [], func1, { pos: DOMUtils.findPos(this) });
                                              };
                                    
                                     //email
                                      var func2 = function (){
                                        payment.date = _self._paymentDate;
                                        payment.amount = gui.fee.value;
                                        payment.userAccount = _self._operator.account;
                                        order.payments[order.payments.length] = payment;
                                        //function() { _self._retrieveCustomer.call(_self); }
                                        
                                        
                                        new RequestUtils()._mwrite('v1payment', [order], [], func11, { pos: DOMUtils.findPos(this) }); 
                                        _self._popupBox2._close(); 
                                        }
                                        
                                        
                                        //no email
                                       var func22 = function (){
                                        payment.date = _self._paymentDate;
                                        payment.amount = gui.fee.value;
                                        payment.userAccount = _self._operator.account;
                                        order.payments[order.payments.length] = payment;
                                        //function() { _self._retrieveCustomer.call(_self); }
                                        
                                        
                                        new RequestUtils()._mwrite('v1payment', [order], [], func1, { pos: DOMUtils.findPos(this) }); 
                                        _self._popupBox2._close(); 
                                        }                                       
                                        
                                        
                                        
                                        var func3 = function() { _self._popupBox2._close();func22();};
                                        MiscUtils.dialog(_self._popupBox2, pos, divr, func2, func3, {t: 'Email Receipt',ok:'Email',cancel:'No Email'});
                                        new DialogInput(divr, pay11, { title: '',default: _default});										
                                    }
                                    

									
                                  };
  
  table = document.createElement('table');
  table.cellPadding = 0;
  table.cellSpacing = 0;
  gui.history.appendChild(table);
  var total = 0;
  for (var i = 0, il = order.payments.length; i < il; i++) {
    var p = order.payments[i];
    if (p.stage != stage) {
      continue;
    }
    if (p.cancelled == 0) {
      total += parseFloat(p.amount, 10);
    }
    
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '12px';
    if (p.cancelled == 1) {
      td.style.textDecoration = 'line-through';
    }
    var method = '';
    if (p.method == 'cash') {
      method = 'c';
    } else if (p.method == 'cheque') {
      method = 'q';
    } else if (p.method == 'bank transfer') {
      method = 'b';
    }
    //td.appendChild(document.createTextNode('Paid: (' + method.toUpperCase() + ')'));
    if (p.method == 'cheque')
    {      
	    var a = document.createElement('a');
	    a.href = '#';
	    a.appendChild(document.createTextNode(method.toUpperCase()));
	    a._payment = p;
	    a.onclick = function() { func1 = function() { _self._popupBox2._close(); };
	                             var pos = DOMUtils.findPos(this);
	                             var div = document.createElement('div');
	                             div.style.verticalAlign = 'top';
	                             div.style.width = '420px';
	                             div.style.color = '#ff0000';
	                             div.style.textAlign = 'left';
	                             div.style.padding = '4px 0 0 10px';
	                             div.style.wordWrap = 'break-word';
	                             div.appendChild(MiscUtils.span('\n' + 'Cheque Number:'+ this._payment.cchequenumber));
	                             div.appendChild(MiscUtils.span('\n' + 'Account Name : '+ this._payment.cAccountname));
	                             div.appendChild(MiscUtils.span('\n' + this._payment.cnote));
	                             MiscUtils.dialog(_self._popupBox2, pos, div, func1, null, {t: 'Cheque Information  ', width: 460, height: 100});
	                             return false;
	                           };
	        
        td.appendChild(document.createTextNode('Paid: ('));
        td.appendChild(a);
        td.appendChild(document.createTextNode(')'));
    }else{
    	td.appendChild(document.createTextNode('Paid: (' + method.toUpperCase() + ')'));
    }

    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 1px';
    if (p.cancelled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('$' + parseFloat(p.amount).toFixed(2)));

    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 3px';
    if (p.cancelled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('Date: ' + SimpleDate.format(p.date)));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 3px';
    if (p.cancelled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(p.userAccount));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 3px';
    
    if (p.cancelled == 0) {
      if(order.finished == 0 && order.disposalstatus == 0)
      {
      a = document.createElement('img');
      a.src = 'images/common/delete.png';
      a.style.cursor = 'pointer';
      a._payment = p;
      

      a.onclick = function() { var pos = DOMUtils.findPos(this);
                               var div = document.createElement('div');
                               var payment = this._payment
                               var func1 = function() { 
                                                        if(payment._text == '')
                                                        {
                                                           window.alert('CAN NOT BE EMPTY');
                                                           return ;
                                                        }
                                                        payment.cancelled = 1;
                                                        payment.cancelledDate = _self._now;
                                                        payment.cancelledOperator = _self._operator.account;
                                                        payment.cancelledMessage = payment._text;
                                                        new RequestUtils()._mwrite('v1payment_c', [payment], [], function() { _self._retrieveCustomer.call(_self); }, { pos: pos });
                                                        _self._popupBox2._close();
                                                      };
                               var func2 = function() { _self._popupBox2._close(); };
                               MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                               new DialogInput(div, payment, { title: '' });
                               return false;
                             };
     
      td.appendChild(a);
      }else if (_self._operator.type == '<?php echo ((is_array($_tmp=@USER_TYPE_ADMIN)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
          a = document.createElement('img');
          a.src = 'images/common/delete.png';
          a.style.cursor = 'pointer';
          a._payment = p;
    
          a.onclick = function() { var pos = DOMUtils.findPos(this);
                                   var div = document.createElement('div');
                                   var payment = this._payment
                                   var func1 = function() { 
                                                            if(payment._text == '')
                                                            {
                                                               window.alert('CAN NOT BE EMPTY');
                                                               return ;
                                                            }
                                                            payment.cancelled = 1;
                                                            payment.cancelledDate = _self._now;
                                                            payment.cancelledOperator = _self._operator.account;
                                                            payment.cancelledMessage = payment._text;
                                                            new RequestUtils()._mwrite('v1payment_c', [payment], [], function() { _self._retrieveCustomer.call(_self); }, { pos: pos });
                                                            _self._popupBox2._close();
                                                          };
                                   var func2 = function() { _self._popupBox2._close(); };
                                   MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                                   new DialogInput(div, payment, { title: '' });
                                   return false;
                                 };
         
          td.appendChild(a);     
      
      }
    } else {
      td.style.color = '#ff0000';
      if (p.cancelledMessage.length > 0) {
        td.appendChild(document.createTextNode((p.cancelledMessage.length > 8) ? p.cancelledMessage.substring(0, 8) + '...' : p.cancelledMessage));
        var a = document.createElement('a');
        a.href = '#';
        a.appendChild(document.createTextNode('All'));
        a._payment = p;
        a.onclick = function() { func1 = function() { _self._popupBox2._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.style.verticalAlign = 'top';
                                 div.style.width = '420px';
                                 div.style.color = '#ff0000';
                                 div.style.textAlign = 'left';
                                 div.style.padding = '4px 0 0 10px';
                                 div.style.wordWrap = 'break-word';
                                 div.appendChild(MiscUtils.span('\n' + this._payment.cancelledMessage));
                                 MiscUtils.dialog(_self._popupBox2, pos, div, func1, null, {t: 'Cancel Reason (' + this._payment.cancelledOperator + ', ' + SimpleDate.format( this._payment.cancelledDate ) + ')', width: 460, height: 100});
                                 return false;
                               };
        td.appendChild(a);
      } else {
        td.appendChild(document.createTextNode('(none)'));
      }
    }
  }
  
  var received = 0;
  for (var i = 0, il = order.payments.length; i < il; i++) {
    var p = order.payments[i];
    if (p.cancelled == 1) {
      continue;
    }
    received += parseFloat(p.amount, 10);
  }
  
  if (total.toFixed(2) > 0) {
    gui.paidc.style.color = '#0066ff';
    gui.paid.style.color = '#0066ff';
  } else {
    gui.paidc.style.color = '#000000';
    gui.paid.style.color = '#000000';
  }
  gui.paid.appendChild(document.createTextNode('$' + total.toFixed(2)));
  gui.due.appendChild(document.createTextNode('$' + ((((order.price * rule.rate * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) - received).toFixed(2) > 0) ? ((order.price * rule.rate * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) - received).toFixed(2) + ' (Inc. ' +  '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '0.00')));
};

HandlePageCustomerOld.prototype._refund = function(gui) {
  var table, tr, td, a, order = DlmanageUtils.order(this._customer.orders, this._orderTrackId), _self = this;
  
  var refund = Expense.instance();
  refund.payee = DlmanageUtils.customerId(this._customer.id);
  refund.method = '';
  refund.particular = 'refund';
  refund.userTrackId = this._operator.trackId;
  refund.userAccount = this._operator.account;
  refund.refundNo = order.e_oid;
  refund.cancelledOperator = this._operator.account;
  
  this._date = this._now;
  gui.date.value = SimpleDate.format(this._date);
  gui.date.onclick = function() { var context = this;
                                  _self._changeDate.call(_self, this, _self._date, function(sd) { _self._date = sd; context.focus(); }, false);
                                };
  
  gui.fee.value = '';
  
  gui.cash.checked = false;
  gui.cheque.checked = false;
  gui.bank.checked = false;
  
  gui.cash.onclick = function() { refund.method = 'C'; };
  gui.cheque.onclick = function() { refund.method = 'Q'; };
  gui.bank.onclick = function() { refund.method = 'B'; };
  
  /*refund*/
  gui.payBtn.onclick = function() { if (gui.fee.value == '' || gui.fee.value == 0) {
                                      window.alert('数值不能为\'' + gui.fee.value + '\'');
                                      return;
                                    } 
                                    if (refund.method == '') {
                                      window.alert('必须选择支付方式');
                                      return;
                                    }
                                    if (!_self._date) {
                                      window.alert('必须选择支付日期');
                                      return;
                                    }
                                    refund.status = 2;
                                    refund.payDate = _self._date;
                                    refund.amount = gui.fee.value;
                                    new RequestUtils()._mwrite('expense', [refund], [], function() { _self._retrieveRefunds.call(_self); }, { pos: DOMUtils.findPos(this) });
                                  };
  
  table = document.createElement('table');
  table.cellPadding = 0;
  table.cellSpacing = 0;
  gui.history.appendChild(table);
  
  var total = 0;
  
  for (var i = 0, il = this._refunds.length; i < il; i++) {
    var r = this._refunds[i];
    
    if (r.refundNo != order.e_oid) {
      continue;
    }
    if (r.status != -1) {
      total += parseFloat(r.amount, 10);
    }
    
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '12px';
    if (r.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('Paid: (' + r.method.toUpperCase() + ')'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 1px';
    if (r.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('$' + r.amount));

    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 3px';
    if (r.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('Date: ' + SimpleDate.format(SimpleDate.fromStamp(r.payDate))));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 3px';
    if (r.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(r.userAccount));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 3px';
    if (r.status != -1) {
      a = document.createElement('img');
      a.src = 'images/common/delete.png';
      a.style.cursor = 'pointer';
      a._refund = r;
      a.onclick = function() { var pos = DOMUtils.findPos(this);
                               var div = document.createElement('div');
                               var refund = this._refund;
                               var func1 = function() { refund.status = -1;
                                                        refund.cancelledDate = _self._now;
                                                        refund.cancelledOperator = _self._operator.account;
                                                        refund.cancelledMessage = refund._text;
                                                        new RequestUtils()._mwrite('expense_c', [refund], [], function() { _self._retrieveRefunds.call(_self); }, { pos: pos });
                                                        _self._popupBox2._close();
                                                      };
                               var func2 = function() { _self._popupBox2._close(); };
                               MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                               new DialogInput(div, refund, { title: '' });
                               return false;
                             };
      td.appendChild(a);
    } else {
      td.style.color = '#ff0000';
      if (r.cancelledMessage.length > 0) {
        td.appendChild(document.createTextNode((r.cancelledMessage.length > 8) ? r.cancelledMessage.substring(0, 8) + '...' : r.cancelledMessage));
        var a = document.createElement('a');
        a.href = '#';
        a.appendChild(document.createTextNode('All'));
        a._refund = r;
        a.onclick = function() { func1 = function() { _self._popupBox2._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.style.verticalAlign = 'top';
                                 div.style.width = '420px';
                                 div.style.color = '#ff0000';
                                 div.style.textAlign = 'left';
                                 div.style.padding = '4px 0 0 10px';
                                 div.style.wordWrap = 'break-word';
                                 div.appendChild(MiscUtils.span('\n' + this._refund.cancelledMessage));
                                 MiscUtils.dialog(_self._popupBox2, pos, div, func1, null, {t: 'Cancel Reason (' + this._refund.cancelledOperator + ', ' + SimpleDate.format(this._refund.cancelledDate) + ')', width: 460, height: 100});
                                 return false;
                               };
        td.appendChild(a);
      } else {
        td.appendChild(document.createTextNode('(none)'));
      }
    }
  }
  if (total.toFixed(2) > 0) {
    gui.refundc.style.color = '#ff0000';
    gui.refund.style.color = '#ff0000';
  } else {
    gui.refundc.style.color = '#000000';
    gui.refund.style.color = '#000000';
  }
  gui.refund.appendChild(document.createTextNode('$' + total.toFixed(2)));
};

/* 
 * 修改日期1Change
 */
HandlePageCustomerOld.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};
/* 
 * 修改日期2Select
 */
HandlePageCustomerOld.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};
/* 
 * 修改日期3Show
 */
HandlePageCustomerOld.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};